// pages/classify/classify.js
const app = getApp();
import http from "../../utils/http";
import util from "../../utils/util";
Page({
	/**
	 * 页面的初始数据
	 */
	data: {
		height: "",
		safehigh: "",
		activeKey: 0,
		menuH: "32px",
		safeTop: `40px`,
		active: 0,
		cate: [],
		active: 0,
		iconList: [
			{
				id: 1,
				pagePath: "pages/index/index",
				text: "首页",
				iconPath: "../../static/tabbar/home.png",
				selectedIconPath: "../../static/tabbar/home_active.png",
			},
			{
				id: 2,
				pagePath: "pages/classify/classify",
				text: "分类",
				iconPath: "../../static/tabbar/classify.png",
				selectedIconPath: "../../static/tabbar/classify_active.png",
			},
			{
				id: 3,
				pagePath: "pages/servers/servers",
				text: "服务者",
				iconPath: "../../static/tabbar/servers.png",
				selectedIconPath: "../../static/tabbar/servers_active.png",
			},
			{
				id: 4,
				pagePath: "pages/cms/cms",
				text: "商家",
				iconPath: "../../static/tabbar/business.png",
				selectedIconPath: "../../static/tabbar/business_active.png",
			},
			{
				id: 5,
				pagePath: "pages/my/my",
				text: "我的",
				iconPath: "../../static/tabbar/my.png",
				selectedIconPath: "../../static/tabbar/my_active.png",
			},
		],
	},

	onLoad(options) {
		this.setData({
			safeTop: `${app.globalData.safeTop}px`,
			menuH: `${app.globalData.menuH}px`,
		});
		this.getInfo();
	},
	onChange(event) {
		const selectedTab = this.data.iconList[event.detail];
		if (selectedTab && selectedTab.pagePath) {
			wx.navigateTo({
				url: `/${selectedTab.pagePath}`,
			});
		}
		this.setData({ active: event.detail });
	},

	cateTap(e) {
		util.skip(
			"/service/catelist/catelist?two_category_id=" +
				e.currentTarget.dataset.item.id +
				"&name=" +
				e.currentTarget.dataset.item.label
		);
	},
	getInfo() {
		http.post("category/getlist", { type: "all" }, true).then((res) => {
			this.setData({
				cate: res.data,
			});
		});
	},
	change(e) {
		this.setData({
			active: e.currentTarget.dataset.index,
		});
	},

	tosearchdetail() {
		wx.navigateTo({
			url: "/service/searchdetail/searchdetail",
		});
	},
	lowerthreshold() {},
	lookid(e) {
		this.setData({
			active: e.currentTarget.dataset.id,
		});
	},
	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage() {
		return {};
	},
});
